//
//  ZTButton.m
//  News
//
//  Created by zhangtao on 2018/11/8.
//  Copyright © 2018年 zt.td. All rights reserved.
//

#import "ZTButton.h"

@implementation ZTButton

-(void)setBadgeNum:(NSInteger)badgeNum{
    NSString *num = @(badgeNum);
    if (!_badgeLab) {
        _badgeLab = [UILabel new];
        _badgeLab.backgroundColor = [UIColor redColor];
        _badgeLab.layer.cornerRadius = 5;
        [self addSubview:_badgeLab];
    }
        CGSize titleSize = [num boundingRectWithSize:
                            CGSizeMake(1000, 10)
                                                 options:NSStringDrawingTruncatesLastVisibleLine |
                            NSStringDrawingUsesLineFragmentOrigin  |
                            NSStringDrawingUsesFontLeading
                                              attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:10]}
                                                 context:nil].size;
        
        CGFloat width = titleSize.width;
        _badgeLab.frame = CGRectMake(self.frame.size.width-width/2, -5, width, 10);
    
        
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
